package com.batch_demo;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class HashDemo {

    public static void main(String[] args) {
        Object object = new Object();

        int hashCode = object.hashCode();
        System.out.println(hashCode);

        hashCode = 8;

        int h = (hashCode >>> 20) ^ (hashCode >>> 12);
        h = h ^ (h >>> 7) ^ (h >>> 4);
        System.out.println(h);


        Map<User, String> map = new HashMap<>();

        for (int i = 0; i < 10000; i ++) {
            map.put(new User(1, "name " + i), i+"value");
        }

        Iterator<Map.Entry<User, String>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

        boolean a = new User(1, "a").equals(new User(1, "a"));
        System.out.println(a);
    }

    static class User {
        private Integer id;
        private String name;

        public User(Integer id, String name) {
            this.id = id;
            this.name = name;
        }

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        @Override
        public int hashCode() {
            return id;
        }

        @Override
        public boolean equals(Object obj) {
//            User u = (User)obj;
//            return this.id.equals(u.getId());
            return super.equals(obj);
        }
    }

}
